#-*- codeing = utf-8 -*-
#@Time : 2020/7/12 21:38
#@Author : 阳某
#@File : list.py
#@Software : PyCharm
# 列表可以存储混合类型
# namelist = []#定义一个空列表
a = [1,2]
b = [3,4]
a.append(b)
print(a)
a.extend(b)#将b列表的每一个元素逐一加入到a列表中
print(a)
namelist = ["张三","李四","王五"]
# 增加
print(namelist)
print("增加前，列表的数据")
for name in namelist:
    print(name)
nametemp = input("请输入要添加的名字：")
namelist.append(nametemp)#列表末尾追加元素
for name in namelist:
    print(name)
a = [0,1,2]
a.insert(1,3)#第一个位置插入元素3
print(a)

# 删除
movieName = ["加勒比海盗","速度与激情8","指环王","辛德勒名单","加勒比海盗"]
print(movieName)
del movieName[2]#在指定位置删除一个元素
movieName.pop()#删除末尾元素
movieName.remove("加勒比海盗")#直接删除指定内容的元素（删除重复的第一个）

# 修改
namelist[1] = "张飞"
print(namelist)

# 查 in   not in
findName = input("请输入你要查找的学生姓名：")
if findName in namelist:
    print("在学员名单中找到了相同的名字")
else:
    print("没有找到")
a = ["a","b","c","a","b"]
print(a.index("a",1,4))  #可以查找指定下标范围的元素，并且返回找到的下标
# print(a.index("a",1,3))#   范围左闭右开
print(a.count("b")) #统计某个元素出现的次数

# 排序和反转
a = [1,4,2,3]
print(a)
a.reverse()#将列表所有元素反转
print(a)
a.sort()#排序升序
print(a)
a.sort(reverse=True)#降序
print(a)

schoolName = [[],[],[]]#有3个空列表的空列表，每一个都是空列表
schoolNames = ["北京大学","清华大学",["南昌大学","南京大学","sdsd"],[1,2,3,2,]]
print(schoolNames[0][0])

import random
offices = [[],[],[]]
names = ["A","B","C","D","E","F","G","H"]
for name in names:
    index = random.randint(0,2)
    offices[index].append(name)
i = 1
for office in offices:
    print("办公室%d的人数为：%d"%(i,len(office)))
    i += 1
    for name in office:
        print("%s"%name,end="\t")
    print("\n")
    print("-"*30)